layui.define(['table', 'form', 'element'], function(exports){
  var $ = layui.$,table = layui.table,form = layui.form, element = layui.element;
  
  var id = $('input[name="id"]').val();
  
  form.on('submit(LAY-update-dbConfig)', function (data) {
      var field = data.field;
      $.ajax({
          type: "post",
          url: layui.setter.webRoot + "/market/cloud/project/db_config/save.do",
          data: field,
          dataType: "json",
          success: function (res) {
              if (res.code == 200) {
                  layer.msg('修改成功', {icon: 1});
              } else {
                  layer.msg(res.msg, {icon: 2});
              }
          }
      });
  });

  form.on('submit(LAY-save)', function (data) {
      var field = data.field;
      $.ajax({
          type: "post",
          url: layui.setter.webRoot + "/market/cloud/project/update.do",
          data: field,
          dataType: "json",
          success: function (res) {
              if (res.code == 200) {
                  layer.msg('修改成功', {icon: 1});
              } else {
                  layer.msg(res.msg, {icon: 2});
              }
          }
      });
  });
  
  //事件
    var active = {
      createDB: function(){
		layer.confirm('确定要创建数据库吗？', function(index){
	    	$.ajax({
	      	  type: "post",
	          url: layui.setter.webRoot + '/market/cloud/project/db/create.do',
	          data:{id:id},
	  		  dataType:"json",
	  		  success:function(res){
	  			if(res.code == 200){
	  				layer.msg('创建数据库成功',{icon: 1});
	  			}else{
	  				layer.msg(res.msg,{icon: 5});
	  			}
	  		  }
	        });
	    	layer.close(index);
	    });
      }
   }
   
   $('.layui-btn.layui-btn-fun').on('click', function(){
       var type = $(this).data('type');
       active[type] ? active[type].call(this) : '';
   });

   exports('market_project_info', {})
});